//
//  DYTabBar.swift
//  IOSweibo09
//
//  Created by mac on 16/3/20.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
let tabBarItemCount = 5
class DYTabBar: UITabBar {

   override func layoutSubviews() {
        super.layoutSubviews()
    let width = frame.width / CGFloat(tabBarItemCount)
    let originFame = CGRect(x: 0, y: 0, width: width, height: frame.height)
    var index = 0
    for view in subviews {
    let cls = NSClassFromString("UITabBarButton")
        if view.isKindOfClass(cls!) {
        view.frame = CGRectOffset(originFame, CGFloat(index) * width ,0 )
            index += index == 1 ? 2 : 1
        }
        composeButton.frame = CGRect(x: width * 2, y: 0, width: width, height: frame.height)
    }
    
    }
    
    
    
    
    
    
    
    
    
    
    private lazy var composeButton: UIButton =
        {
    let button = UIButton()
            button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
            button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
            button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
            button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
            self.addSubview(button)
            return button
    }()
  
}
